package preprocessor;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Process {
	
	private static final String EMPTY = "";
	private static final String NEWLINE = "\n";

    public static String removePunctuation (String text) // tested
    {
        return text.replaceAll(CONSTANTS.PUNCTUATION_REGEX, CONSTANTS.CHAR_SPACE);
    }

    public static String removeBraces (String text) // tested
    {
        return text.replaceAll(CONSTANTS.REGEX_BRACES, CONSTANTS.CHAR_SPACE);
    }
    
    public static String removeNumbers (String text) // tested
    {
        return text.replaceAll(CONSTANTS.REGEX_NUMBERS, CONSTANTS.CHAR_SPACE);
    }

    public static String preprocessText (String text)
    {
        return removeNumbers(removePunctuation(removeBraces(text))).replace(NEWLINE, EMPTY).trim().toLowerCase();
    }
    
	public static void main(String[] args) throws IOException {
		String inputpath = args[0];
		String outputpath = args[1];
		File root = new File(inputpath);
		int i = 0;
		for(File c: root.listFiles())
		{
			System.out.println(++i);
			BufferedReader br = new BufferedReader(new FileReader(c));
			StringBuffer sb = new StringBuffer();
			String line = null;
			while((line=br.readLine())!=null)
			{
				sb.append(line);
				sb.append("\n");
			}
			String out = preprocessText(sb.toString());
			BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outputpath+c.getName())));
			bw.write(out);
			br.close();
			bw.flush();
			bw.close();
		}
	}
}
